<?php

$g_main_table_cellspacing = "5";
$g_main_table_cellpadding = "0";


function PrintPageTitle($title)
{
    global $r;
    echo '
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr height="59">
	<td width="5"><img src="'.$r.'images/r2_rainbow/left.gif" width="5" height="59" alt="" border="0"></td>
	<td background="'.$r.'images/r2_rainbow/center.gif">
        <div class=pageTitle>'.$title.'</div>
    </td>
	<td width="322"><img src="'.$r.'images/r2_rainbow/right.gif" width="322" height="59" alt="" border="0"></td>
</tr>
</table>
';
}


class CHtmlRectangle
{
    var $info;
    
    function CHtmlRectangle($info)
    {
        $this->info = $info;
    }
    
    function PrintBegin($options=array())
    {
        $this->PrintBeginOrEnd("begin", $options);
    }
    
    function PrintEnd($options=array())
    {
        $this->PrintBeginOrEnd("end", $options);
    }
                     
    /* Privat function */
    function PrintBeginOrEnd($what, $options=array())
    {
        global $r;
        
        $n = $this->info["n"]; /* name */
        $s = $this->info["s"]; /* size */
        
        if (!isset($options["w"])) $options["w"] = "";
        if (!isset($options["h"])) $options["h"] = "";
        
        $bgc = $this->info["bgcolor"];
        
        if (!isset($this->info["noborder"]))
        {
            $td_tc = 'background="'.$r.'images/'.$n.'/tc.gif"';
            $td_vl = 'background="'.$r.'images/'.$n.'/vl.gif"';
            $td_vr = 'background="'.$r.'images/'.$n.'/vr.gif"';
            $td_bc = 'background="'.$r.'images/'.$n.'/bc.gif"';
        }
        else
        {
            $td_tc =
            $td_vl =
            $td_vr =
            $td_bc = 'bgcolor="'.$bgc.'"';
        }
        
        if ($what == "begin") {
            echo
'<table width="'.$options["w"].'" height="'.$options["h"].'" border="0" cellspacing="0" cellpadding="0">
<tr height="'.$s.'">
	<td width="'.$s.'"><img src="'.$r.'images/'.$n.'/tl.gif" width="'.$s.'" height="'.$s.'" alt="" border="0"></td>
	<td '.$td_tc.'></td>
	<td width="'.$s.'"><img src="'.$r.'images/'.$n.'/tr.gif" width="'.$s.'" height="'.$s.'" alt="" border="0"></td>
</tr>
<tr>
	<td '.$td_vl.'></td>
	<td bgcolor="'.$bgc.'" valign="top" style="'.@$options["td_style"].'">
';
        }

        if ($what == "end") {
            echo
'   </td>
	<td '.$td_vr.'></td>
</tr>
<tr height="'.$s.'">
	<td><img src="'.$r.'images/'.$n.'/bl.gif" width="'.$s.'" height="'.$s.'" alt="" border="0"></td>
	<td '.$td_bc.'></td>
	<td><img src="'.$r.'images/'.$n.'/br.gif" width="'.$s.'" height="'.$s.'" alt="" border="0"></td>
</tr>
</table>
';
        }
    }
}

$g_html_rect_main = new CHtmlRectangle(
    array('n'=>"r1", 's'=>8, 'bgcolor'=>"#FFFFFF"));

$g_html_rect_slogan = new CHtmlRectangle(
    array('n'=>"r2", 's'=>5, 'bgcolor'=>"#FEF1DD"));

$g_html_rect_blue_area = new CHtmlRectangle(
    array('n'=>"r3", 's'=>5, 'bgcolor'=>"#E1EDF3"));

$g_html_rect_light_blue_area = new CHtmlRectangle(
    array('n'=>"r3_light", 's'=>5, 'bgcolor'=>"#F2F7FA"));

$g_html_rect_white_area = new CHtmlRectangle(
    array('n'=>"r4", 's'=>5, 'bgcolor'=>"#FFFFFF"));

$g_html_rect_footer = new CHtmlRectangle(
    array('n'=>"r5", 's'=>5, 'bgcolor'=>"#E1EDF3", 'noborder'=>true));

/* TODO: move to another file */
function process_template($template, $data)
{
    foreach ($data as $k => $v)
    {
        $template = str_replace("[%".$k."%]", $v, $template);
    }
    return $template;
}



function make_with_nbsp($s)
{
    return str_replace(" ", "&nbsp;", $s);
}

function make_link($page, $template_active, $template_inactive, $data)
{
    global $p;
    if ($page != $p) {
        return process_template($template_active, $data);
    }
    else {
        return process_template($template_inactive, $data);
    }
}
?>